package com.lagou.server;

import com.lagou.client.module.Student;
import com.lagou.client.module.User;

import java.util.HashMap;
import java.util.Map;

public class ServerDao {

    private static Map<String,Integer> stdMap = new HashMap<>();

    /**
     * 管理员登录信息校验
     * @param user
     * @return
     */
    public boolean serverManagerCheck(User user){
        if("admin".equals(user.getUsername()) && "123456".equals(user.getPassword())){
            return true;
        }
        return false;
    }


    /**
     * 添加学员
     * @param student
     * @return
     */
    public boolean stdAdd(Student student){
        stdMap.put(student.getUsername(),student.getAge());
        return true;
    }

    /**
     * 修改学员
     * @param student
     * @return
     */
    public boolean stdUpdate(Student student){
        if(stdMap.get(student.getUsername())!=null){
            stdMap.put(student.getUsername(),student.getAge());
            return true;
        }else{
            return false;
        }
    }

    /**
     * 删除学员
     * @param student
     * @return
     */
    public boolean stdDel(Student student){
        if(stdMap.get(student.getUsername())!=null){
            stdMap.remove(student.getUsername());
            return true;
        }else{
            return false;
        }
    }

    /**
     * 获取学员信息
     * @param name
     * @return
     */
    public Student getStd(String name){
        Student student = new Student();
        if(stdMap.get(name)!=null){
            student.setUsername(name);
            student.setAge(stdMap.get(student.getUsername()));
        }
        return student;
    }

}
